public class Solution {
    public int tribonacci(int n) {
        int t0 = 0, t1 = 1, t2 = 1;
        if (n == 0) {
            return t0;
        } else if (n == 1) {
            return t1;
        } else if (n == 2) {
            return t2;
        }
        int count = 2;
        int ret = 0;
        while (count < n) {
            count++;
            ret = t0 + t1 + t2;
            t0 = t1;
            t1 = t2;
            t2 = ret;
        }
        return ret;
    }

    public int tribonacci2(int n) {
        int[] ret = new int[38];
        ret[0] = 0;
        ret[1] = 1;
        ret[2] = 1;
        int count = 3;
        while (count <= n) {
            ret[count] = ret[count - 1] + ret[count - 2] + ret[count - 3];
            count++;
        }
        return ret[n];
    }
}
